import homepage from '@/lib/request/homepage'
import { RootState } from '../index'
import { Commit } from 'vuex'
import { IResponse } from '@/lib/service'

export interface HomepageState {}
const initState: HomepageState = {}

const getters = {}

const actions = {
  downloadResource(
    context: {
      commit: Commit
      state: HomepageState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    // 下载
    return homepage
      .downloadResource(payload)
      .then((data: IResponse) => data.data)
  },
  getNewsDetail(
    context: {
      commit: Commit
      state: HomepageState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    // 公告通知详情
    return homepage.getNewsDetail(payload).then((data: IResponse) => data.data)
  },
  queryResourceList(
    context: {
      commit: Commit
      state: HomepageState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    // 获取下载列表
    return homepage
      .queryResourceList(payload)
      .then((data: IResponse) => data.data)
  },
  queryNewsList(
    context: {
      commit: Commit
      state: HomepageState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    // 新闻列表
    return homepage.queryNewsList(payload).then((data: IResponse) => data.data)
  },
  queryFAQList(
    context: {
      commit: Commit
      state: HomepageState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    // FAQ列表
    return homepage.queryFAQList(payload).then((data: IResponse) => data.data)
  },
}

const mutations = {
  setStateData(state: HomepageState, data: any) {
    // eslint-disable-next-line no-param-reassign
    state = Object.assign(state, data)
  },
}

export default {
  namespaced: true,
  state: initState,
  getters,
  actions,
  mutations,
}
